import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pylab import rcParams
%matplotlib inline
rcParams['figure.figsize'] = 20, 20
pd.set_option('display.max_columns', 100)
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from mpl_toolkits.axes_grid1 import make_axes_locatable
import seaborn as sns
pd.options.display.float_format = '{:,.2f}'.format
def plot_correlation(df, features):
corr = df[features].corr()
fig, ax = plt.subplots(figsize=(10, 10));
im = ax.matshow(corr, cmap='RdBu', vmin=-1, vmax=1);
for i in range(len(features)):
for j in range(len(features)):
c = corr.iloc[j,i]
ax.text(i, j, '%.2f' % c, color='w', fontsize=10);#, va='center', ha='center');
plt.xticks(range(len(features)), features, rotation = 90);
plt.yticks(range(len(features)), features);
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.5)
plt.colorbar(im, cax=cax)
plt.show();
1.1. Loading and inspecting the original 'meaningful' CSPS dataset
folder = '/projects/st_all_airbus_all_data_analysis/ISAMI/CSPS/CSPS_Thibault/CSPS_test/'
file = 'CSPS_output_and_meaningful_values_100000.csv'
csps = pd.read_csv(folder + file, index_col=False, na_values=['---','----','-----','N/A','--','------'])
csps.info()
csps.head()
1.2. Re-shuffling and alligning properly the DoE with CSPS outputs according to correct Test_case_ID
deo_inputs = csps.iloc[:,63:]
csps_inputs = csps.iloc[:,0:63]
def natural_sort(df, col):
df[['_str', '_int']] = df[col].str.extract(r'([a-zA-Z]*)(\d*)')
df['_int'] = df['_int'].astype(int)
return df.sort_values(by=['_str', '_int']).drop(['_int', '_str'], axis=1)
csps_inputs_sorted = natural_sort(csps_inputs, 'Test_case_ID').reset_index(drop=True)
csps_inputs_sorted.head()
csps_sorted = pd.concat([csps_inputs_sorted,deo_inputs],axis=1)
csps_sorted.shape
1.3. Removing rows that are NA across all failure modes (in case there are any)
outputs = ['Panel_local_buckling (SYM.)','Panel_local_buckling (ROT.)', \
'General_Buckling','Post-Buckling_RF','Stringer_local_buckling_RF', \
'IDT_RF','Post-Buckling_Cut-Off','Skin_DT','SkinUnderOmega_DT', \
'DTStringer','PlainStrength']
inputs = ['t', 'p0', 'p90', 'chiD1', 'chiD2', 'chiD3', 'tc', 'p0c', 'p90c', 'tw', \
'p0w', 'p90w', 'h', 'b', 'alpha', 'Nxx', 'Nyy', 'Nxy','bf']
plies = ['Nbplies','Nbplies_cap','Nbplies_web']
csps_sorted = csps_sorted.dropna(subset=outputs,how='all')
csps_sorted.shape
csps_sorted.dropna(subset=outputs,how='any').shape
1.4. Splitting the original dataset into inputs and outputs
csps_outputs = csps_sorted[outputs]
csps_inputs = csps_sorted[inputs]
csps_plies = csps_sorted[plies]
csps_outputs.info()
csps_inputs.info()
csps_plies.info()
1.5. Check if design criteria was met
def design_criteria(inputs):
rules = [(1.472 <= inputs['t']).all() and (inputs['t'] <= 6.808).all(),
(20 <= inputs['alpha']).all() and (inputs['alpha'] <= 40).all(),
(180 <= inputs['b']).all() and (inputs['b'] <= 300).all(),
(0 <= inputs['p0']).all() and (inputs['p0'] <= 1).all(),
(0 <= inputs['p90']).all() and (inputs['p90'] <= 1).all(),
# (-1 <= inputs['chiD1']).all() and (inputs['chiD1'] <= 1).all(),
# (-1 <= inputs['chiD2']).all() and (inputs['chiD2'] <= 1).all(),
# (-1 <= inputs['chiD3']).all() and (inputs['chiD3'] <= 1).all(),
(20 <= inputs['h']).all() and (inputs['h'] <= 50).all(),
(1.143 <= inputs['tw']).all() and (inputs['tw'] <= 3.175).all(),
(0 <= inputs['p0w']).all() and (inputs['p0w'] <= 1).all(),
(0 <= inputs['p90w']).all() and (inputs['p90w'] <= 1).all(),
(0 <= inputs['p0c']).all() and (inputs['p0c'] <= 1).all(),
(0 <= inputs['p90c']).all() and (inputs['p90c'] <= 1).all(),
(inputs['tc'] >= inputs['tw']).all(),
# rule for tc?,NXX,NYY, and NXY?
# What about BF as an input?
# BA and BW?
]
if all(rules):
print("Design criteria has been met!")
design_criteria(csps_inputs)
print(csps_inputs['chiD1'].max(),csps_inputs['chiD1'].min())
sum(csps_inputs['chiD1'] > 1)
print(csps_inputs['chiD2'].max(),csps_inputs['chiD2'].min())
sum(csps_inputs['chiD2'] > 1)
sum(csps_inputs['chiD2'] < -1)
print(csps_inputs['chiD3'].max(),csps_inputs['chiD3'].min())
1.6. Inspecting CSPS plies relationship
csps_plies.describe([.9, .95, .99])
csps_plies.hist()
plt.show()
print('Number of plies in the cap is higher or equal than in the web', ((csps_plies['Nbplies_cap'] >= csps_plies['Nbplies_web']).sum() / csps_plies.shape[0] * 100), '% of the time')
print('Number of plies in the cap is higher than in the web', ((csps_plies['Nbplies_cap'] > csps_plies['Nbplies_web']).sum() / csps_plies.shape[0] * 100), '% of the time')
print('Number of plies in the cap is higher or equal than in the skin', ((csps_plies['Nbplies_cap'] >= csps_plies['Nbplies']).sum() / csps_plies.shape[0] * 100), '% of the time')
print('Number of plies in the cap is higher than in the skin', ((csps_plies['Nbplies_cap'] > csps_plies['Nbplies']).sum() / csps_plies.shape[0] * 100), '% of the time')
plot_correlation(csps_plies, plies)
sns.pairplot(csps_plies);
plt.show();
1.7. Inspecting inputs
csps_inputs.describe([.9, .95, .99])
csps_inputs.hist()
plt.show()
plot_correlation(csps_inputs, inputs)
sns.pairplot(csps_inputs)
plt.show()